<?php
require './include/global.php';
require './include/validate.php';
require './include/all_left.php';
require_once './include/advisory_db.php';
$status = $_SESSION['status'];
//print_r($_SESSION);
$smarty->compile_check = true;
include("./check/checkpostjob.php");

$jobid = ($_GET[id])?$_GET[id]:$_POST[id];

$rs  = $DB->fetch_one_array("SELECT * FROM pa_job WHERE `jo_uid`=".$_SESSION[uid]." AND `jo_id` =".$jobid );
$_GET[view]=="op"&& $rs  = $DB->fetch_one_array("SELECT * FROM pa_job WHERE `jo_id` =".$jobid );

$rsp = $DB->fetch_one_array("SELECT * FROM pa_job WHERE `jo_utype`='".$_SESSION[usertype]."' AND `jo_id` ='".$jobid."' AND `jo_uid`='".$_SESSION[uid]."'");

if($rs[jo_id]!=''){$jobid = $rs[jo_id];}
if(empty($rsp)){
    $otherjob = 1;
}

if(empty($rs)||$jobid==''){
	  echo "<meta http-equiv=\"refresh\" content=\"0;URL=errorall.php?errid=rc_1017\">";
	   exit;
}
if($_GET[action]=="delete"){
       $sql = "DELETE FROM pa_job WHERE `jo_id`=".$jobid;
       $DB->query($sql);
	   redirect2("myjobs.php");
	   exit;
}else{
	  
	    
		ob_clean();
		ob_start();
		if($_GET[action]=="view"){
		$title   = "<h2>View Job</h2>";
		$cpforms->formheader(array('title'=>'Job Record','name'=>'article'));
		$view = 1;
		}else{
		$cpforms->formheader(array('title'=>'Job Record','name'=>'article'));
		$title   = "Post/Edit Job(<font color=red>*</font>=Required Field)";
		$only = 1;
		}
		//$cpforms->formheader(array('title'=>'Job Record','name'=>'article'));
		$cpforms->makehidden(array('name'=>'id','value'=>$jobid));
		$cpforms->makehidden(array('name'=>'offset','value'=>$offset));
		$cpforms->makehidden(array('name'=>'action','value'=>'upd_job'));
		$cpforms->gethightext(array('text'=>"Create Date",'value'=>date("m/d/Y",$rs[jo_regtime]),'view'=>"1"));
		if($rs[jo_updtime]==0){$rs[jo_updtime] = $rs[jo_regtime];}
		$cpforms->gethightext(array('text'=>"Last Updated",'value'=>date("m/d/Y",$rs[jo_updtime]),'view'=>"1"));
		$cpforms->gethightext(array('text'=>"ER Job Req#",'value'=>$rs[jo_id],'view'=>"1"));
		
        if(($_SESSION[usertype]=='recruiter')||($_SESSION[usertype]=='employer'&&$otherjob != 1)||$_SESSION[usertype]=='candidate'){

		$cpforms->longline(array('title'=>"Post Options"));
		$rs['jo_contact'] = explode(",", $rs["jo_contact"]);
		if(!$view){
		$cpforms->getBoxes(array('one'=>1,'text'=>"Contact Guideline",'only'=>$only,'name'=>"jo_contact[]",'view'=>"$view",'selected'=>$rs[jo_contact],'option'=>$jobcontact));
		}
		$cpforms->makeselect(array('one'=>1,'only'=>1,'text'=>"Job Category",'name'=>"jo_cat",'selected'=>"$rs[jo_cat]",'view'=>"$view",'option'=> $jobCatOption));

		if ($_SESSION[usertype] != "candidate" && $rs[jo_cat] == '2' && $rs[jo_bonus]!='') {
			$smarty->assign("show_jobsplitfee",1);
			$cpforms->gethightext(array('text'=>"Job Split Fee ($ or %)",'name'=>"jo_bonus", 'value'=>nl2br($rs[jo_bonus]),'view'=>"$view"));
		}

		//BEGIN zxd 2011.09.15 hidden for Trail
		if('Trial' != $status)
		{
			$cpforms->longline(array('title'=>"Job Poster Information"));
			$cpforms->gethightext(array('text'=>"Name",'name'=>"jo_copname",'only'=>$only,'value'=>"$rs[jo_copname]",'view'=>"$view"));
			if($rs[jo_copurl] != ''){
				$cpforms->gethightext(array('text'=>"Website",'name'=>"jo_copurl",'value'=>"$rs[jo_copurl]",'view'=>"$view",'url'=>1));
			}
			if($view != 1){
			$cpforms->gethightext(array('text'=>"Contact Name",'name'=>"jo_priname",'value'=>"$rs[jo_priname]",'view'=>"$view",'icon'=>"'This information is for record keeping and internal use only.  It is not viewable by the public or recruiters.', WIDTH, 200, SHADOW, true"));
			$cpforms->gethightext(array('text'=>"Contact Email",'name'=>"jo_priemail",'value'=>"$rs[jo_priemail]",'view'=>"$view",'icon'=>"'This information is for record keeping and internal use only.  It is not viewable by the public or recruiters.', WIDTH, 200, SHADOW, true"));
			$cpforms->gethightext(array('text'=>"Contact Phone",'name'=>"jo_priphone",'value'=>"$rs[jo_priphone]",'view'=>"$view",'icon'=>"'This information is for record keeping and internal use only.  It is not viewable by the public or recruiters.', WIDTH, 200, SHADOW, true"));
			$cpforms->gethightext(array('text'=>"Hiring Comany Information",'name'=>"jo_hircompany",'value'=>"$rs[jo_hircompany]",'view'=>"$view",'icon'=>"'Your client or hiring company information here.', WIDTH, 200, SHADOW, true"));
			}

			if(($rs['jo_copculture'] != '' && $rs['jo_copculture'] != 'N/A') || ($rs['jo_copbenefit'] != '' && $rs['jo_copbenefit'] != 'N/A')){
				$cpforms->longline(array('title'=>"Hiring Company Information"));
			}
			if($rs['jo_copculture'] != '' && $rs['jo_copculture'] != 'N/A'){
				$cpforms->maketextarea(array('text'=>"About the Hiring Company",'name'=>"jo_copculture",'value'=>"$rs[jo_copculture]",'view'=>"$view",'icon'=>"'Describe in 250 characters or less.  You may edit this later.', WIDTH, 200, SHADOW, true"));
			}
			if($rs['jo_copbenefit'] != '' && $rs['jo_copbenefit'] != 'N/A'){
				$cpforms->maketextarea(array('text'=>"Hiring Company Manager and Benefits",'name'=>"jo_copbenefit",'value'=>"$rs[jo_copbenefit]",'view'=>"$view",'icon'=>"'Describe in 250 characters or less.  You may edit this later.', WIDTH, 200, SHADOW, true"));
			}
			}
		}

		$cpforms->longline(array('title'=>"Job Information"));

		if($view == 1){
			echo '<tr class="firstalt" nowrap=""><td width="40%">Job Title:</td>
                       <td width="60%" style="font-weight:bold; color:blue">'.$rs[jo_title].'</td>
            </tr>';
		}else{
				$cpforms->gethightext(array('text'=>"Job Title",'name'=>"jo_title",'only'=>$only,'value'=>"$rs[jo_title]",'view'=>"$view"));
		}

		if($rs['jo_vdate'] != ''){
		$cpforms->gethightext(array('text'=>"Job Valid By Date",'name'=>"jo_vdate",'only'=>$only,'value'=>"$rs[jo_vdate]",'view'=>"$view"));
		}
		$cpforms->makeselect(array('text'=>"Job Fill Status",'only'=>$only,'name'=>"jo_status",'view'=>"$view",'selected'=>"$rs[jo_status]",'option'=> $jobfillstatus));
		if($otherjob!=1){
		$cpforms->makeselect(array('text'=>"Job Priority",'name'=>"jo_priority",'only'=>$only,'selected'=>"$rs[jo_priority]",'view'=>"$view",'option'=> $priority));
		}
		$cpforms->makeselect(array('text'=>"Job Type",'only'=>$only,'name'=>"jo_type",'view'=>"$view",'selected'=>"$rs[jo_type]",'option'=>$jobtype));

		$cpforms->makeselect(array('text'=>"Job Industry",'name'=>"jo_category",'only'=>$only,'selected'=>"$rs[jo_category]",'view'=>"$view",'option'=> $jobcategory));
		$cpforms->makeselect(array('text'=>"Job Function",'name'=>"jo_function",'only'=>$only,'selected'=>"$rs[jo_function]",'view'=>"$view",'option'=> $jobfunction));
		
		
		if($otherjob!=1 && $rs[jo_copreq] != ''){
		$cpforms->gethightext(array('text'=>"Company Internal Req#",'name'=>"jo_copreq",'value'=>"$rs[jo_copreq]",'view'=>"$view",'icon'=>"'Enter an internal job code if available.', WIDTH, 200, SHADOW, true"));
		}
		$cpforms->gethightext(array('text'=>"No. of Open Positions",'name'=>"jo_positions",'only'=>$only,'value'=>"$rs[jo_positions]",'view'=>"$view"));
					$cpforms->gethightext(array('text'=>"Compensation(USD)",'name'=>"jo_salrange",'only'=>$only,'value'=>"$rs[jo_salrange]",'view'=>"$view"));

		if($_SESSION[usertype]=='recruiter'||$_SESSION[usertype]=='employer'){
		if($otherjob!=1){
		$cpforms->gethightext(array('text'=>"Work Address",'only'=>$only,'name'=>"jo_address",'value'=>"$rs[jo_address]",'view'=>"$view"));
		}
		}
		$cpforms->gethightext(array('text'=>"Location - City",'name'=>"jo_city",'only'=>$only,'value'=>"$rs[jo_city]",'view'=>"$view"));
		$cpforms->makeselect(array('text'=>"Location - State/Region",'name'=>"jo_state",'only'=>$only,'selected'=>"$rs[jo_state]",'view'=>"$view",'option'=> $state));
		$cpforms->makeselect(array('text'=>"Location - Country",'name'=>"jo_country",'only'=>$only,'selected'=>"$rs[jo_country]",'view'=>"$view",'option'=> $country));
		$cpforms->gethightext(array('text'=>"Location - Zip Code",'name'=>"jo_zip",'only'=>$only,'value'=>"$rs[jo_zip]",'view'=>"$view"));
		
		if($rs[jo_howfar] != 0 && $rs[jo_howfar] != '' ){
		$cpforms->makeselect(array('text'=>"Will consider candidates how far from company location?",'name'=>"jo_howfar",'only'=>$only,'selected'=>"$rs[jo_howfar]",'view'=>"$view",'option'=> $location));
		}
		if($rs[jo_jobtravel] != 0 && $rs[jo_jobtravel] != '' ){
		$cpforms->makeselect(array('text'=>"Job Travel Requirement(%)",'only'=>$only,'name'=>"jo_jobtravel",'selected'=>"$rs[jo_jobtravel]",'view'=>"$view",'option'=> $travel));
		}
		//$cpforms->maketextarea(array('text'=>"About the Hiring Manager",'name'=>"jo_hiringmanager",'value'=>"$rs[jo_hiringmanager]",'view'=>"$view",'icon'=>"'Please describe the hiring manager for this position in 250 characters or less.  You may edit this later.', WIDTH, 200, SHADOW, true"));
		$cpforms->longline(array('title'=>"Job Qualifications"));
		if($rs[jo_mer] != '' ){
			$cpforms->gethightext(array('text'=>"Minimum Education Requirement",'name'=>"jo_mer",'only'=>$only,'value'=>"$rs[jo_mer]",'view'=>"$view"));
		}
		if($rs[jo_myrwe] != 0 ){
		$cpforms->makeselect(array('text'=>"Minimum Years of Relevant Work Experience",'name'=>"jo_myrwe",'only'=>$only,'selected'=>"$rs[jo_myrwe]",'view'=>"$view",'option'=> $yearexp2));
		}
		if($rs[jo_ypme] != 0 ){
		$cpforms->makeselect(array('text'=>"Years of People Management Experience",'name'=>"jo_ypme",'only'=>$only,'selected'=>"$rs[jo_ypme]",'view'=>"$view",'option'=> $yearexp2));
		}
		if($rs[jo_yplr] != 0 ){
		$cpforms->makeselect(array('text'=>"Years of Profit & Loss Responsibility",'name'=>"jo_yplr",'only'=>$only,'selected'=>"$rs[jo_yplr]",'view'=>"$view",'option'=> $yearexp2));
		}
		if($rs[jo_license] != '' ){
		$cpforms->gethightext(array('text'=>"Industry License Requirement",'name'=>"jo_license",'value'=>"$rs[jo_license]",'view'=>"$view"));
		}
		if($rs[jo_language] != '' ){
		$cpforms->gethightext(array('text'=>"Required Language Skills",'name'=>"jo_language",'value'=>"$rs[jo_language]",'view'=>"$view"));
		}
		$cpforms->gethightext(array('text'=>"Authorized to Work in Location",'name'=>"jo_authorized",'only'=>$only,'value'=>"$rs[jo_authorized]",'view'=>"$view",'icon'=>"'Please indicate the Country or Region where job candidates must have the authorization or permit to work.', WIDTH, 200, SHADOW, true"));
		$cpforms->gethighradio(array('text'=>"U.S. Government Security Clearance",'name'=>"jo_usgsc",'selected'=>"$rs[jo_usgsc]",'view'=>"$view",'icon'=>"'Indicate whether or not this job requires U.S. government clearance.', WIDTH, 200, SHADOW, true"));
		if('Trial' != $status && trim($rs[jo_description]) != '')
		{
			$cpforms->maketextarea2(array('text'=>"Job Description ",'name'=>"jo_description","only"=>$only,'value'=>"$rs[jo_description]",'view'=>"$view",'icon'=>"'Please include all job details here in 3,000 characters or less.  You may edit this later.', WIDTH, 200, SHADOW, true"));
		}
		
		
		if(($_SESSION[usertype]=='recruiter'||$_SESSION[usertype]=='employer') && $rs[jo_public] != ''){
		$cpforms->maketextarea(array('text'=>"Public Note",'name'=>"jo_public",'value'=>"$rs[jo_public]",'view'=>"$view",'icon'=>"'Post a note about this job to Recruiters.', WIDTH, 200, SHADOW, true"));
		if($otherjob!=1  && $rs[jo_private] != ''){
		//$cpforms->maketextarea(array('text'=>"Private Note",'name'=>"jo_private",'value'=>"$rs[jo_private]",'view'=>"$view",'icon'=>"'Post a note about this job to yourself.', WIDTH, 200, SHADOW, true"));
		}
        }

		if($_GET[action]!="view"){
			$cpforms->formfooter(array('confirm'=>3));
		}elseif($_GET[action]=='edit'){
		    $cpforms->formfooter();
		}

		if($_GET[action]=="view"){
			echo "<tr class=\"tbhead\"><td colspan=\"2\" align=\"center\" bgcolor=\"#F0F0F0\"><input class=\"bginput button-secondary\" type=\"button\" value=\"Back\" onclick=\"history.go(-1);\">&nbsp;&nbsp;&nbsp;";
			if($_SESSION[usertype]=="recruiter"&&$otherjob==1){
				if($rs[jo_status]==2){
					//$checked = " disabled ";
				}
				//check if they are friends
				$re = $DB->fetch_one_array("select re_uid from pa_contact where `re_isapproved` = '1' and re_aliasid = '".$jobid."' and re_uid = '".$_SESSION['uid']."'");
				if( $re['re_uid'] ){
					$btn_submitcandidate =  "<input class=\"button-secondary\" type=\"button\" value=\"Submit Candidate\" onclick=\"location.href='submitapplicant.php?jid=".$jobid."'\" $checked>&nbsp;&nbsp;&nbsp;";
					$smarty->assign("btn_submitcandidate",$btn_submitcandidate);
					echo $btn_submitcandidate;
				}
				
				if($_SESSION[usertype]=="recruiter")$contactUrl = "recruitercontact.php";
				if($_SESSION[usertype]=="candidate")$contactUrl = "resumecontactemployer.php";
				
				$btn_sendmessage =  "<input class=\"button-secondary\"  type=\"button\" value=\"Send Message\"  onclick=\"location.href='".$contactUrl."?jid=$jobid'\" ".$checked.">";
				$smarty->assign("btn_sendmessage",$btn_sendmessage);

				
				echo $btn_sendmessage;
			}elseif($_SESSION[usertype] == "candidate"){
				if($rs[jo_status]==2){$checked = ' disabled ';}
				$btn_submitresume = "<input  class=\"button-secondary\" type=\"button\" value=\"Submit Resume\" onclick=\"location.href='resumesubmitresume.php?jid=$jobid'\" $checked>";
				$smarty->assign("btn_submitresume",$btn_submitresume);
				echo $btn_submitresume;
			}
			echo "</td></tr></table></td></tr></table>\n";
			$smarty->assign('fancybox',1);
		}
		$reg_data = ob_get_contents();
		ob_end_clean();


		$smarty->assign('title',$title);

		if($err!=''){
		$smarty->assign("err",$err);
		}
		$smarty->assign("reg",$reg_data);

		$smarty->display('header.tpl');
		$smarty->display('allleft.tpl');
		if($view == 1){	

			$rs['jo_jobtravel'] = ($rs['jo_jobtravel']>0)?$travel[$rs['jo_jobtravel']]:'';
			$rs['jo_howfar'] = ($rs['jo_howfar']>0)?$location[$rs['jo_howfar']]:'';
			$rs['jo_yplr'] = ($rs['jo_yplr']>0)?$yearexp2[$rs['jo_yplr']]." yrs":'';
			$rs['jo_ypme'] = ($rs['jo_ypme']>0)?$yearexp2[$rs['jo_ypme']]." yrs":'';
			$rs['jo_myrwe']	 = ($rs['jo_myrwe']>0)?$yearexp2[$rs['jo_myrwe']]." yrs":'';
			$rs['jo_function'] = $jobfunction[$rs['jo_function']];
			$rs['jo_status'] = $jobfillstatus[$rs['jo_status']];
			$rs['jo_type'] = $jobtype[$rs['jo_type']];
			$rs['jo_regtime'] = date("m/d/Y",$rs['jo_regtime']);
			$rs['jo_cat'] = $jobCatOption[$rs['jo_cat']];
			$rs['jo_state'] = $state[$rs['jo_state']];
			$rs['jo_country'] = $country[$rs['jo_country']];

			$smarty->assign("rs",$rs);
			$smarty->display('jobaction.tpl');
		}else{
			$smarty->display('reg.tpl');
		}
		$smarty->display('allright.tpl');
		$smarty->display('footer.tpl');
}
?>
